﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../Content/css/bootstrap.min.css" />
    <link rel="stylesheet" href="../Content/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../Content/css/ace.min.css" />
    <link rel="stylesheet" href="../Content/css/jframe.css" />
</head>
<body ng-app="formApp" class="page-content">
    <div ng-controller="formCtrl">
        <form class="form-horizontal" role="form">
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="code">目标模型</label>
                <div class="input-group col-xs-10">
                    <input type="text" placeholder="目标模型" class="form-control input-mask-date" ng-model="model2.name" readonly="readonly" />
                    <span class="input-group-btn">
                        <button class="btn btn-sm btn-info" type="button" ng-click="interactive.onPickModel2()">
                            <i class="icon-search bigger-110"></i>
                            选择
                        </button>
                    </span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="multiplicity">多样性</label>
                <div class="col-sm-9">
                    <select class="col-xs-10 col-sm-5" ng-model="multiplicity" id="multiplicity">
                        <option value="1">one-one</option>
                        <option value="2">one-one?</option>
                        <option value="3">one-many</option>
                        <option value="4">one-many?</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="type">关联类型</label>
                <div class="col-sm-9">
                    <select class="col-xs-10 col-sm-5" ng-model="type" id="type">
                        <option value="1">聚合</option>
                        <option value="2">组合</option>
                    </select>
                </div>
            </div>
        </form>
        <div class="center">
            <div class="btn-group ">
                <button class="btn btn-sm btn-purple" ng-click="interactive.onOK()">
                    <i class="icon-save bigger-125"></i>
                    提 交
                </button>
            </div>
            <div class="btn-group">
                <button class="btn btn-sm btn-info" ng-click="interactive.onCancel()">
                    <i class="icon-undo bigger-125"></i>
                    返 回
                </button>
            </div>
        </div>
    </div>
    <script src="../Config.js"></script>
    <script src="../Content/js/jquery-1.10.2/jquery-1.10.2.min.js"></script>
    <script src="../Content/js/bootstrap.min.js"></script>
    <script src="../Content/js/promise/Promise.js"></script>
    <script src="../Content/js/ace-elements.min.js"></script>
    <script src="../Content/js/ace.min.js"></script>
    <script src="../Content/js/bootbox.min.js"></script>
    <script src="../Content/js/angular-1.2.29/angular-1.2.29.min.js"></script>

    <script src="../Content/js/jquery.gritter.min.js"></script>
    <script src="../Content/js/cppei/cppei.view.js"></script>
    <script src="../Content/js/cppei/cppei.paginationPlugin.js"></script>
    <script>
        cppei.install();

        angular.module('formApp', []).controller("formCtrl", function ($scope, $http) {
            $scope.model1Id = cppei.url.getQueryString()['id'];

            $scope.service = {
            };

            $scope.interactive = {
                onPickModel2: function () {
                    cppei.showDialog('选择模型', jframe.getUrl('html/picker-model.html'), function (result, data) {
                        if (result) {
                            $scope.model2 = data;
                            $scope.$apply();
                        }
                    }, { width: 600, height: 580 });
                },
                onCancel: function () {
                    cppei.closeDialog(false, null);
                },
                onOK: function () {
                    var model1Multiplicity = 0;
                    var model2Multiplicity = 0;
                    switch ($scope.multiplicity) {
                        case 1:
                            model1Multiplicity = 1;
                            model2Multiplicity = 1;
                            break;
                        case 3:
                            model1Multiplicity = 1;
                            model2Multiplicity = 3;
                            break;
                        case 4:
                            model1Multiplicity = 1;
                            model2Multiplicity = 4;
                            break;
                        case 2:
                        default:
                            model1Multiplicity = 1;
                            model2Multiplicity = 2;
                            break;
                    }

                    $http({
                        method: 'post',
                        url: jframe.getUrl('Api/Model/CreateRelation'),
                        cache: false,
                        data: {
                            model1Id: $scope.model1Id,
                            model2Id: $scope.model2.id,
                            model1Multiplicity: model1Multiplicity,
                            model2Multiplicity: model2Multiplicity,
                            type: $scope.type
                        }
                    }).success(function (result, status) {
                        //debugger;
                        if (result.isSuccess) {
                            //创建成功后删除该条信息
                            cppei.growl('创建成功!');
                            cppei.closeDialog(true, null);
                        } else {
                            cppei.growlError(result.message);
                        }
                    }).error(function (result, status) {
                        cppei.growlError(result.message);
                    });
                }
            }
        });
    </script>
</body>
</html>
